home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / map / extract.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-12  |  1.5 KB  |  80 lines

  1. /*
  2.  *    extract.c
  3.  *
  4.  *    Changes map database from binary to text
  5.  */
  6.  
  7. #include <stdio.h>
  8.  
  9. main(argc, argv)
  10. int    argc;
  11. char    *argv[];
  12. {
  13.     FILE    *fpi, *fpo;
  14.     struct    { int code, lat, lon; } coord;
  15.     int    n, degrees, minutes;
  16.     char    type[80], tmp[16];
  17.  
  18.     if (argc != 3)  {
  19.         printf("Usage: extract input.pnt output.asc\n");
  20.         exit(1);
  21.     }
  22.  
  23.     if ((fpi = fopen(argv[1], "rb")) == (FILE *)NULL)  {
  24.            printf("\007Error: Can't locate Database '%s'\n", argv[1]);
  25.            exit(1);
  26.     }
  27.  
  28.     if ((fpo = fopen(argv[2], "w")) == (FILE *)NULL)  {
  29.            printf("\007Error: Can't create Database '%s'\n", argv[2]);
  30.            exit(1);
  31.     }
  32.  
  33.     while (fread((char *)&coord, sizeof coord, 1, fpi) > 0)  {
  34.         itoa(coord.code, tmp, 10);
  35.         strcpy(type, tmp);
  36.         strcat(type, ", ");
  37.  
  38.         if (coord.lat < 0)
  39.             strcat(type, "-");
  40.  
  41.         minutes = abs(coord.lat) % 60;
  42.         degrees = abs(coord.lat) / 60;
  43.  
  44.         itoa(degrees, tmp, 10);
  45.         strcat(type, tmp);
  46.         strcat(type, ".");
  47.         itoa(minutes, tmp, 10);
  48.  
  49.         if (minutes < 10)
  50.             strcat(type, "0");
  51.  
  52.         strcat(type, tmp);
  53.         strcat(type, ", ");
  54.  
  55.         if (coord.lon < 0)
  56.             strcat(type, "-");
  57.  
  58.         minutes = abs(coord.lon) % 60;
  59.         degrees = abs(coord.lon) / 60;
  60.  
  61.         itoa(degrees, tmp, 10);
  62.         strcat(type, tmp);
  63.         strcat(type, ".");
  64.         itoa(minutes, tmp, 10);
  65.  
  66.         if (minutes < 10)
  67.             strcat(type, "0");
  68.  
  69.         strcat(type, tmp);
  70.         strcat(type, "\n");
  71.  
  72.         fwrite(type, sizeof(char), strlen(type), fpo);
  73.     }
  74.  
  75.     fclose(fpi);
  76.     fclose(fpo);
  77.  
  78.     exit(0);
  79. }
  80.